package Java.ThreadPool;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

//线程池的三种分类
public class ThreadPoolDemo1 {

    public static void main(String[] args) {
        //一池五线程
//        ExecutorService  threadpool1= Executors.newFixedThreadPool(5);

        //一池一线程
//        ExecutorService threadpool2=Executors.newSingleThreadExecutor();

        //一池可扩容线程
        ExecutorService threadpool3 = Executors.newCachedThreadPool();


        try {
            //10个顾客请求
            for (int i = 1; i <= 10; i++) {
                //执行
                threadpool3.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + " 办理业务");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭
            threadpool3.shutdown();
        }


    }
}
